package com.abel.bigwater.dataserver.model.qdies

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Assert.assertEquals
import org.junit.Test
import org.slf4j.LoggerFactory

class MainAskNowTest {
    @Test
    fun fillAsk485Now() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.Ask485Now
            data = MainAsk485NowData().also { it.internalAddr = 1 }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask 485 now", DEMO_ASK_485_NOW, str)
    }

    @Test
    fun fillAskAnalogNow() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskAnalogNow
            data = MainAskAnalogNowData().also { it.internalAddr = 1 }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask analog now", DEMO_ASK_ANALOG_NOW, str)
    }

    @Test
    fun fillAskPulseNow() {
        val buf = Unpooled.buffer()
        val p = MainPacket().apply {
            address = BcdString(byteArrayOf(12, 0, 0, 1), true)
            func = FuncType.AskPulseNow
            data = MainAskPulseNowData().also { it.internalAddr = 1 }

            fill(buf)
        }

        val str = BcdString.create(buf, buf.readableBytes()).bcdString
        lgr.info(str)
        assertEquals("ask pulse now", DEMO_ASK_PULSE_NOW, str)
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MainAskNowTest::class.java)

        const val DEMO_ASK_485_NOW = "68120000011801016b16"

        const val DEMO_ASK_ANALOG_NOW = "68120000011901016a16"

        const val DEMO_ASK_PULSE_NOW = "68120000011a01016916"
    }
}